<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
	<div class="wrapper wrapper-content ">
		<div class="row">
			<div class="col-sm-12">
				<div class="ibox float-e-margins">
					<div class="ibox-content">
						<form class="form-horizontal m-t" id="signupForm">
						<input id="id" name="id" th:value="${pact.id}"  type="hidden">
							<div class="form-group">
								<label class="col-sm-3 control-label">合同图片：</label>
								<div class="col-sm-8">
									<input type="hidden" id="fileId" name="fileId" th:value="${pact.fileId}" >
									<img id="showImg" th:src="@{${fileDO.url}}" style="width: 100%;cursor: pointer;" >
									<input  type="file" class="hidden" id="file" name="file" onchange="uploadFile(this.files)" />
								</div>

								<script type="text/javascript">
                                    $("#showImg").click(function () {
                                        $("#file").click();
                                    });

                                    function uploadFile(files) {
                                        var type = files[0].type;
                                        if(type.indexOf("image") < 0){
                                            layer.msg('请上传图片格式...', {
                                                icon: 2
                                            });
                                            return false;
                                        }
                                        var size = files[0].size;
                                        if ((size / 1024 / 1024) > 2) {
                                            layer.msg('图片大小不能超过2M...', {
                                                icon: 2
                                            });
                                            return false;
                                        }
                                        console.log("size=" + size);
                                        var formData = new FormData();
                                        formData.append("file", files[0]);
                                        $.ajax({
                                            data: formData,
                                            type: "POST",
                                            url: "/common/sysFile/upload",    // 图片上传出来的url，返回的是图片上传后的路径，http格式
                                            cache: false,
                                            contentType: false,
                                            processData: false,
                                            dataType: "json",
                                            success: function (data) {//data是返回的hash,key之类的值，key是定义的文件名
                                                $("#showImg").attr("src", data.fileName);
                                                $("#fileId").val(data.sysFileId);
                                            },
                                            error: function () {
                                                layer.msg('上传失败', {
                                                    icon: 2
                                                });
                                            }
                                        });
                                    }
								</script>
							</div>
									<div class="form-group">
								<div class="col-sm-8 col-sm-offset-3">
								<!-- 	<button type="submit" class="btn btn-primary">返回</button> -->
									<a class="btn btn-primary" href="/phry/pact">返回</a>
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>
	</div>
	</div>
	<div th:include="include::footer"></div>
	<script type="text/javascript" src="/js/appjs/phry/pact/edit.js">
	</script>
</body>
</html>
